import traceback

from peewee_migrate import Router
from apiCenter.src.lib.Model import BaseModel
import apiCenter.src.model.dao as dao

class ModelMigrate():
    @staticmethod
    def ini_database(model):
        try:
            BaseModel._meta.database.create_tables(model)
            print('Database init finished!')
        except:
            traceback.print_exc()

    @staticmethod
    def create_migrate(model_name=None):
        try:
            router = Router(BaseModel._meta.database, ignore='basemodel')
            if model_name is None:
                router.create()
            else:
                router.create(auto=model_name)
            # router.run()
        except:
            traceback.print_exc()

    @staticmethod
    def action_migrate(migrate_name=''):
        try:
            router = Router(BaseModel._meta.database)
            router.run(name=migrate_name)
        except:
            traceback.print_exc()


# db = peewee.SqliteDatabase(DatabaseConfig.db_host)
# db.create_tables([DbUser])
# db.close()
ModelMigrate.create_migrate(dao)
ModelMigrate.action_migrate()
